package com.cccyy.zookeeper;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class ZkDigestPassword {
    public static void main(String[] args) {
        try {
            // 密码明文
            String password = "dubbo123";
            // 生成认证字符串 "username:password"
            String authenticationString = "dubbo:" + password;

            // 获取MD5加密对象
            MessageDigest digester = MessageDigest.getInstance("MD5");
            // 执行加密
            byte[] digestedPassword = digester.digest(authenticationString.getBytes());

            // 将加密后的数据转换为十六进制字符串
            StringBuilder hexString = new StringBuilder();
            for (byte b : digestedPassword) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }

            // 打印生成的digest密码
            System.out.println(hexString.toString());
        } catch (NoSuchAlgorithmException e) {
            System.out.println(e.getMessage());
        }
    }
}
